namespace TrackMe.Backend.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Jobs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TaskId = c.Int(nullable: false),
                        StartTime = c.DateTime(nullable: false),
                        EndTime = c.DateTime(nullable: false),
                        Description = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Tasks", t => t.TaskId, cascadeDelete: true)
                .Index(t => t.TaskId);
            
            CreateTable(
                "dbo.Tasks",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ExternalId = c.Int(nullable: false),
                        ProjectId = c.Int(nullable: false),
                        ParentId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Projects", t => t.ProjectId, cascadeDelete: true)
                .ForeignKey("dbo.Tasks", t => t.ParentId)
                .Index(t => t.ProjectId)
                .Index(t => t.ParentId);
            
            CreateTable(
                "dbo.Projects",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ExternalId = c.Int(nullable: false),
                        ServerId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.TfsServers", t => t.ServerId, cascadeDelete: true)
                .Index(t => t.ServerId);
            
            CreateTable(
                "dbo.TfsServers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Url = c.String(maxLength: 2048),
                        LastSync = c.DateTime(nullable: false),
                        Name = c.String(maxLength: 2048),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Guid = c.String(maxLength: 80),
                        Name = c.String(maxLength: 80),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.JobInProgresses",
                c => new
                    {
                        JobId = c.Int(nullable: false),
                        SingletonLock = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.JobId)
                .ForeignKey("dbo.Jobs", t => t.JobId)
                .Index(t => t.JobId);
            
            CreateTable(
                "dbo.JobToClockOuts",
                c => new
                    {
                        JobId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.JobId)
                .ForeignKey("dbo.Jobs", t => t.JobId)
                .Index(t => t.JobId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.JobToClockOuts", new[] { "JobId" });
            DropIndex("dbo.JobInProgresses", new[] { "JobId" });
            DropIndex("dbo.Projects", new[] { "ServerId" });
            DropIndex("dbo.Tasks", new[] { "ParentId" });
            DropIndex("dbo.Tasks", new[] { "ProjectId" });
            DropIndex("dbo.Jobs", new[] { "TaskId" });
            DropForeignKey("dbo.JobToClockOuts", "JobId", "dbo.Jobs");
            DropForeignKey("dbo.JobInProgresses", "JobId", "dbo.Jobs");
            DropForeignKey("dbo.Projects", "ServerId", "dbo.TfsServers");
            DropForeignKey("dbo.Tasks", "ParentId", "dbo.Tasks");
            DropForeignKey("dbo.Tasks", "ProjectId", "dbo.Projects");
            DropForeignKey("dbo.Jobs", "TaskId", "dbo.Tasks");
            DropTable("dbo.JobToClockOuts");
            DropTable("dbo.JobInProgresses");
            DropTable("dbo.Users");
            DropTable("dbo.TfsServers");
            DropTable("dbo.Projects");
            DropTable("dbo.Tasks");
            DropTable("dbo.Jobs");
        }
    }
}
